package com.liming.admin.controller;

import com.liming.common.pojo.dto.stock.AddStockFlowDTO;
import com.liming.common.pojo.dto.stock.StockFlowPageQuery;
import com.liming.common.pojo.dto.stock.StockPageQuery;
import com.liming.common.pojo.dto.stock.UpdStockQuantityDTO;
import com.liming.common.pojo.vo.PageVO;
import com.liming.common.pojo.vo.stock.StockFlowVO;
import com.liming.common.pojo.vo.stock.StockVO;
import com.liming.common.pojo.vo.stock.StockDashboardVO;
import com.liming.common.result.LMResult;
import com.liming.stock.client.StockClient;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * @author liming
 * @date 2025/1/23
 */
@Slf4j
@RestController
@AllArgsConstructor
@Tag(name = "库存接口-Web")
@RequestMapping("/admin/stock")
public class StockController {

    private final StockClient stockClient;

    @Operation(summary = "分页 - 库存相关信息（仓库）")
    @GetMapping
    public LMResult<PageVO<StockVO>> page(StockPageQuery query) {
        return LMResult.success(stockClient.page(query));
    }

    @Operation(summary = "分页 - 所有库存流水记录")
    @GetMapping("flow")
    public LMResult<PageVO<StockFlowVO>> pageFlow(StockFlowPageQuery query) {
        return LMResult.success(stockClient.pageFlow(query));
    }

    @Operation(summary = "库存流水大屏")
    @GetMapping("store-dashboard")
    public LMResult<StockDashboardVO> stockDashboard(@RequestParam String scope) {
        return LMResult.success(stockClient.stockDashboard(scope));
    }

    @Operation(summary = "新增 - 库存流水")
    @PostMapping("flow")
    public LMResult<Boolean> addStockFlow(@RequestBody AddStockFlowDTO addStockFlowDTO) {
        return LMResult.success(stockClient.addStockFlow(addStockFlowDTO));
    }

    @Operation(summary = "更新 - 总库存&预警库存")
    @PutMapping("updStockQuantity")
    public LMResult<Boolean> updStockQuantity(@RequestBody UpdStockQuantityDTO updStockQuantityDTO) {
        return LMResult.success(stockClient.updStockQuantity(updStockQuantityDTO));
    }

    @Operation(summary = "更新 - 启用|禁用")
    @PutMapping("updStatus/{id}")
    public LMResult<Boolean> updStatus(@PathVariable Long id) {
        return LMResult.success(stockClient.updStatus(id));
    }

    @Operation(summary = "更新 - 出库")
    @PutMapping("out/{id}")
    public LMResult<Boolean> out(@PathVariable Long id, @RequestParam Integer quantity) {
        return LMResult.success(stockClient.out(id, quantity));
    }
}
